//
//  TF_RecommendViewCell.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/3/21.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TF_RecommendViewCell: UITableViewCell {
    @objc public var cellWidth:CGFloat = 0
    @objc public let QC = UIImageView()
    
    @objc public let merchandise = UIImageView()
    @objc public let title = UILabel()
    @objc public let now_Price = UILabel()

    @objc public var model:TFgoods?{
        didSet {
            if ((model) != nil)
            {
                let url:URL? = URL.init(string: model!.img as String)
                self.merchandise.sd_setImage(with: url, completed: nil)
                
                let qrcode:URL? = URL.init(string: model!.qrcode as String)
                self.QC.sd_setImage(with: qrcode, completed: nil)
                
                
                self.title.text = model?.name;
                

                
                var text:NSString = model!.now_Price as NSString;
                if (text.length > 0) {
                    text = (text as String) + "元" as NSString

                let fontAttributeNameStr = NSMutableAttributedString.init(string: text as String)

                    let attr12: [NSAttributedString.Key : Any] = [.font: UIFont.PingFang(size: 12) as Any,]
                    fontAttributeNameStr.addAttributes(attr12, range: NSRange(location: 0, length: text.length - 1))
                    
                    
                    fontAttributeNameStr.addAttribute(.foregroundColor, value: UIColor(red: 255/255.0, green: 55/255.0, blue: 55/255.0, alpha: 1.0), range: NSRange(location: 0, length: text.length - 1))
                



                    let attr15: [NSAttributedString.Key : Any] = [.font: UIFont.PingFang(size: 15) as Any,]
                    fontAttributeNameStr.addAttributes(attr15, range: NSRange(location: text.length - 1, length: 1))
                    

                    fontAttributeNameStr.addAttribute(.foregroundColor, value: UIColor(red: 255/255.0, green: 55/255.0, blue: 55/255.0, alpha: 1.0), range: NSRange(location: text.length - 1, length:1))
                    
                    // 3.给label赋值
                    self.now_Price.attributedText = fontAttributeNameStr;
                }else{
                    let fontAttributeNameStr = NSMutableAttributedString.init(string: "" as String)
                    
                    self.now_Price.attributedText = fontAttributeNameStr;
                }
              
                
                
            }
        }
    }
    
 

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
   
        self.merchandise.clipsToBounds = true;
        self.merchandise.backgroundColor = UIColor.clear
        self.contentView.addSubview(self.merchandise)
      
        
    
        self.title.numberOfLines = 0;
        self.contentView.addSubview(self.title)
        self.title.font = UIFont.PingFang(size: 14)
        self.title.textColor = UIColor(red: 50/255.0, green: 54/255.0, blue: 61/255.0 , alpha: 1.0)
        
      
        self.now_Price.numberOfLines = 0;
        self.contentView.addSubview(self.now_Price)
        self.now_Price.textColor = UIColor(red: 255/255.0, green: 55/255.0, blue: 55/255.0 , alpha: 1.0)
        

        
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        self.merchandise.frame = CGRect(x: 10, y: 8, width: 61, height: 61)
        self.merchandise .layer.cornerRadius = 2;
        
        self.title.frame = CGRect(x: 78.5, y: 8, width: 137, height: 20)
   
        
        self.now_Price.frame = CGRect(x: 78.5, y: self.merchandise.frame.maxY, width: 45, height: 21)
        
    
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    


}
